package com.itheima.config;

import com.itheima.common.EsProperties;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(EsProperties.class)
public class EsConfig {

    /**
     * 将RestHighLevelClient客户端对象交给IOC容器管理
     * @param es
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient(EsProperties es) {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(new HttpHost(es.getHost(), es.getPort())));
        return client;
    }

}
